#!/usr/bin/python
# -*- coding: utf-8 -*-
import omen.engine.core.services as cs

## application container description


class ApplicationParamKeys(object):
    appli_name_key = 'name'

## error raised when service addition fails
class ApplicationAddServiceError(RuntimeError):
    pass

## error raised when service deletion fails
class ApplicationRemoveServiceError(RuntimeError):
    pass

## base class of application container
class Application(object):
    def __init__(self, application_name):
        self.name = application_name
        self.services = {}
    
    ## add a service to the service container
    def add_service(self, obj):
        if issubclass(obj.__class__, cs.Service):
            self.services[obj.name] = obj
        else:
            raise ApplicationAddServiceError('Unable to add service to Application !')
    
    ## remove a service from the container
    def remove_service_by_name(self, service_name):
        if service_name.strip() in self.services.keys():
            del self.services[service_name]
        else:
            raise ApplicationRemoveServiceError('Unable to remove service, key not found !')
        
    
        
    
        